package com.py.credit.freemarker;

import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class MyFreeMarkerView extends FreeMarkerView {

    private static final String CONTEXT_PATH = "base";

    @Override
    protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
        String basePath = request.getContextPath();
        if ("".equals(basePath) || "/".equals(basePath)) {
            basePath = "";
        }
        basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + basePath;

        model.put(CONTEXT_PATH, basePath);
        super.exposeHelpers(model, request);
    }

}